package com.TP.www.service;

import com.TP.www.dao.impl.CustomerDAO;
import com.TP.www.dao.impl.MerchantDAO;
import com.TP.www.po.Customer;
import com.TP.www.po.Merchant;
import com.TP.www.po.User;

/**
 * @author 邱彦祥
 * 余额接口
 */
public interface AssetPort {
    /**
     * 获取收益
     * @param num 账户余额增加的金额
     */
     void add(double num);

    /**
     * 更新数据库数据
     * @param user 当前登入用户
     * @param num   最终账户余额
     */
    static void refresh(User user,double num){
        String sql;
        if(user instanceof Customer){
            sql ="update customer set asset = ? where id = ?;";
            new CustomerDAO().executeUpdate(sql,num,user.getId());
        }else if (user instanceof Merchant){
            sql ="update merchant set asset = ? where id = ?;";
            new MerchantDAO().executeQuery(sql,num,user.getId());
        }
    }
}
